package com.htc.model.utils;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import com.htc.model.dto.FitnessGroupDTO;
import com.htc.model.dto.WellnessOverviewDTO;
import com.htc.model.dto.WellnessSchChildDTO;
import com.htc.utils.CommonObjects;

public class FitnessModel {
	public static FitnessModel instance;

	public static FitnessModel getInstance() {
		if (instance == null)
			instance = new FitnessModel();
		return instance;
	}

	public ArrayList<FitnessGroupDTO> getAllFitnessGroup(Context context) {
		ArrayList<FitnessGroupDTO> arrData = new ArrayList<FitnessGroupDTO>();
		String sql = "SELECT * FROM fitness_group";
		DBHelper db = DBHelper.getInstance(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			FitnessGroupDTO model = new FitnessGroupDTO();
			model.setFitnessGroupId(c.getString(c
					.getColumnIndex("fitness_group_id")));
			model.setFitnessGroupName(c.getString(c
					.getColumnIndex("fitness_group_name")));
			model.setFitnessGroupNameAr(c.getString(c
					.getColumnIndex("fitness_group_name_ar")));
			model.setFitnessGroupAddedDate(c.getString(c
					.getColumnIndex("added_date")));
			arrData.add(model);
		}
		c.close();
		db.close();
		return arrData;
	}

	@SuppressLint("NewApi")
	public ArrayList<WellnessSchChildDTO> query(String paramString,
			Context context) {
		ArrayList<WellnessSchChildDTO> arrData = new ArrayList<WellnessSchChildDTO>();

		String sql = "SELECT fitness_class_name,fitness_class_image,fitness_schedule_start_time,fitness_schedule_instructor_id,fitness_class_description,fitness_schedule_day,fitness_schedule_class_id, fitness_class_description_ar FROM fitness_class INNER JOIN fitness_schedule ON fitness_class_id = fitness_schedule_class_id WHERE fitness_schedule_day ='"
				+ paramString + "'";
		DBHelper db = DBHelper.getInstance(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			WellnessSchChildDTO dto = new WellnessSchChildDTO();
			String sql2 = "SELECT * FROM instructor WHERE instructor_id = '"
					+ c.getString(3) + "'";

			if (!c.getString(3).isEmpty()) {
				dto.setWellnessSchInstructorId(c.getString(3));
				Cursor c2 = db.Excutequery(sql2);
				while (c2.moveToNext()) {
					if (c2.getCount() > 0) {
						dto.setWellnessSchTitle(c2.getString(1));
						dto.setWellnessSchTitleAr(c2.getString(2));
						if (!c.getString(1).isEmpty())
							dto.setWellnessSchImage(c.getString(1));
						if (!c.getString(2).isEmpty())
							dto.setWellnessSchTime(c.getString(2));
						dto.setWellnessSchClassId(c.getString(6));
						if (!c.getString(4).isEmpty()) {
							dto.setWellnessSchDesc(c.getString(4));
							dto.setWellnessSchDescAr(c.getString(7));
						}
						if (!c.getString(5).isEmpty())
							dto.setWellnessSchDay(c.getString(5));
						arrData.add(dto);

					}
					c2.close();
				}

			}
		}
		c.close();
		db.close();
		return arrData;
	}

	public ArrayList<WellnessOverviewDTO> getwellnessOverviewDayTime(
			String paramString, Context context) {
		ArrayList<WellnessOverviewDTO> arrData = new ArrayList<WellnessOverviewDTO>();
		String sql = "SELECT * FROM fitness_schedule WHERE fitness_schedule_class_id ='"
				+ paramString + "'";
		DBHelper db = DBHelper.getInstance(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			WellnessOverviewDTO dto = new WellnessOverviewDTO();
			dto.setWellnessclassId(c.getString(c
					.getColumnIndex("fitness_schedule_id")));
			dto.setWellnessoverviewday(c.getString(c
					.getColumnIndex("fitness_schedule_day")));
			dto.setWellnessoverviewtime(c.getString(c
					.getColumnIndex("fitness_schedule_start_time")));
			arrData.add(dto);
		}
		c.close();
		db.close();
		return arrData;
	}

}
